package day19;

public class TestDeadLock {
	public static void main(String[] args) {
		Object o1 = new Object();
		Object o2 = new Object();
		Thread t1 = new DeadThread1(o1, o2);
		Thread t2 = new DeadThread2(o1, o2);
		t1.start();
		t2.start();
	}
}

class DeadThread1 extends Thread{
	private Object o1;
	private Object o2;
	public DeadThread1(Object o1, Object o2){
		this.o1 = o1;
		this.o2 = o2;
	}
	public void run(){
		synchronized(o1){
			try{
				Thread.sleep(10);
			}catch(Exception e){
				e.printStackTrace();
			}
			synchronized(o2){
				System.out.println("Haha OK! of DeadThread1");
			}
		}
	}
}

class DeadThread2 extends Thread{
	private Object o1;
	private Object o2;
	public DeadThread2(Object o1, Object o2){
		this.o1 = o1;
		this.o2 = o2;
	}
	public void run(){
		synchronized(o2){
			try{
				Thread.sleep(10);
			}catch(Exception e){
				e.printStackTrace();
			}
			synchronized(o1){
				System.out.println("Haha OK! of DeadThread2");
			}
		}
	}
}